<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>销售单位管理</title>
    <#include "${ctx.getContextPath()}/css.jsp" parse=true encoding="utf-8">
</head>
<body>
<#include "${ctx.getContextPath()}/js.jsp" parse=true encoding="utf-8">
<div class="page">
    <header class="bar bar-nav">
        <a class="button button-link button-nav pull-left external " href="/company/companyList"
           data-transition='slide-out'>
            <span class="icon icon-left"></span>
            返回
        </a>
        <h1 class="title">销售单位新增</h1>
    </header>
    <div class="content">
        <input type="hidden" id="uuid" name="uuid" value="${sysCompany.uuid!''}">
        <div class="list-block">
            <ul>
                <li>
                    <div class="item-content">
                        <div class="item-inner">
                            <div class="item-title label">单位名称:</div>
                            <div class="item-input">
                                <input type="text" id="companyName" name="companyName"
                                       value="${sysCompany.companyName!''}" placeholder="请输入单位名称">
                            </div>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="item-content">
                        <div class="item-inner">
                            <div class="item-title label">单位地址:</div>
                            <div class="item-input">
                                <input type="text" id="companyAddress" value="${sysCompany.companyAddress!''}"
                                       name="companyAddress" placeholder="请输入单位地址">
                            </div>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="item-content">
                        <div class="item-inner">
                            <div class="item-title label">法人姓名:</div>
                            <div class="item-input">
                                <input type="text" id="corporation" value="${sysCompany.corporation!''}"
                                       name="corporation" placeholder="请输入法人姓名">
                            </div>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="item-content">
                        <div class="item-inner">
                            <div class="item-title label">联系电话:</div>
                            <div class="item-input">
                                <input type="text" id="phonyNumber" value="${sysCompany.phonyNumber!''}"
                                       name="phonyNumber" placeholder="请输入联系电话">
                            </div>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="item-content">
                        <span style="color: red;font-size: 16px;text-align: center;" id="errorMsg"
                              name="errorMsg"></span>
                    </div>
                </li>
            </ul>
        </div>
        <div class="content-block">
            <div class="row">
                <div class="col-50"><a href="${ctx.getContextPath()}/company/companyList"
                                       class="button button-big button-fill button-danger external ">返回</a></div>
                <div class="col-50">
                    <#if pageType ?? && pageType =='show' >
                    <#else>
                    <a href="#" onclick="submit();"
                       class="button button-big button-fill button-success external">提交</a>
                </#if>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    function submit() {
        if (vilation()) {
            $.ajax({
                type: "POST",//方法类型
                dataType: "json",
                url: "/company/add",
                data: {
                    uuid:$("#uuid").val(),
                    companyName: $("#companyName").val(),
                    companyAddress: $("#companyAddress").val(),
                    corporation: $("#corporation").val(),
                    phonyNumber: $("#phonyNumber").val(),
                },
                success: function (result) {
                    var msg = result.message;
                    $("#errorMsg").text(msg);
                    if (result.code == 200) {
                        location.href = "${ctx.getContextPath()}/company/companyList";
                    } else {
                        return;
                    }
                },
                error: function () {
                    alert("系统异常！");
                }
            });

        } else {
            return;
        }
    }

    function vilation() {
        $("#errorMsg").text("");
        var companyName = $("#companyName").val();
        var corporation = $("#corporation").val();
        if (companyName == null || companyName == "") {
            $("#errorMsg").text("请填写单位名称");
            return false;
        } else if (corporation == null || corporation == "") {
            $("#errorMsg").text("请填写法人姓名名称");
            return false;
        } else {
            return true;
        }

    }
</script>
</body>
</html>